package com.ajz.config;

import javax.servlet.http.HttpServletRequest;

import com.ajz.config.jwt.JwtTokenUtil;
import com.ajz.config.jwt.SpringUtil;
import com.ajz.manager.entity.Member;
import com.ajz.manager.service.MemberService;

public class AppUserUtil {
	/**
	 * 获取当前登陆用户
	 * @return
	 */
	public static Member getUser(HttpServletRequest request) {
		String authHeader = request.getHeader("authorization");
         String token = authHeader.substring(7);
         JwtTokenUtil jwtTokenUtil = SpringUtil.getBean(JwtTokenUtil.class);
         MemberService memberService = SpringUtil.getBean(MemberService.class);
         String username = jwtTokenUtil.getUsernameFromToken(token);
		return memberService.findByLoginName(username);
	}
}
